<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        #d1,#d2{
            width: 100px;
            height: 100px;
            border: 1px solid red;
        }
        #d1{
            margin-left: 50px;
            margin-top: 100px;
            margin-bottom: 30px;
            /*四个方向添加外边距*/
            margin: 50px;
            /*上下和左右*/
            margin: 50px 100px;
            /*上右下左顺时针赋值*/
            margin: 50px 100px 150px 200px;
        }
        #d2{
            /*上下相邻的兄弟元素外边距取最大值(由于外边距塌陷(合并)导致)*/
            margin-top: 50px;
        }
        span{
            border: 1px solid blue;
        }
        #s1{
            /*行内元素上下外边距无效*/
            margin-right: 50px;
        }
        #s2{
            /*左右相邻兄弟元素彼此添加外边距,两者相加*/
            margin-left: 50px;
        }
        #big{
            width: 200px;
            height: 200px;
            background-color: green;
            overflow: hidden;/*解决粘连问题*/
        }
        #big>div{
            width: 50px;
            height: 50px;
            background-color: red;
            margin-left: 50px;
            /*外边距塌陷问题会导致父子元素重叠时,给元素添加外边距取最大值,最终父子元素会粘连在一起*/
            margin-top: 150px;
        }
    </style>
</head>
<body>
<div id="big">
    <div></div>
</div>
<span id="s1">span1</span><span id="s2">span2</span>
<div id="d1">div1</div>
<div id="d2">div2</div>
</body>
</html>